import { checkTable, type table } from "@/ts/table/tableData";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useTable = defineStore("table", () => {
    const storgedTable = ref({} as {[index:string]:table})
    function getTable(roomId:string):table{
        let table = storgedTable.value[roomId]
        if(table==undefined){
            table = {type:'simple'}
            storgedTable.value[roomId]= table
        }
        return table
    }
    return {storgedTable,getTable}
}, {
    persist: {
        serializer:{
            serialize(data) {
                return JSON.stringify(data)
            },
            deserialize(data) {
                let state = JSON.parse(data)
                for(let key of Object.keys(state)){
                    state[key]=checkTable(state[key])
                }
                return state
            },
        }
    }
})